<!DOCTYPE html>
<html lang="zh_CN">
<head>
    <#-- 包含其他文件的内容 -->
    <#include "../common/header.ftl"/>
    <script src="/js/plugins/jqueryForm/jquery.form.js"></script>
    <script src="/js/plugins/ckeditor/ckeditor.js"></script>
        <script src="/js/My97DatePicker/WdatePicker.js"></script>


        <script>
            $(function () {

                //日期插件的使用
                $("#searchForm [name=beignDate]").click(function () {
                    WdatePicker({
                        readOnly:true,
                        maxDate:new Date()
                    });
                });
                $("#searchForm [name=endDate]").click(function () {
                    WdatePicker({
                        readOnly:true,
                        minDate:$("#searchForm [name=beginDate]").val(),
                        maxDate:new Date()
                    });
                });

                   //模态框中的选择文件按钮
                   $("#fileButten").click(function () {
                       $("#fileBtn").click();
                   })
                   //提交图片
                   $("#fileBtn").change(function () {
                       if ($(this).val()) {
                           $("#fileForm").ajaxSubmit(function (data) {
                               if (data.url) {
                                   $("#coverImg").prop("src",data.url)
                               }
                           })
                       }
                   })

                   //添加编辑按钮
                   $(".inputBtn").click(function () {
                       var json = $(this).data("json");
                       console.log(json);
                       $("#coverImg").prop("src","");
                       $("#editForm input").val("");
                       if (json) {
                           $("#editForm input[name='id']").val(json.id);
                           $("#editForm input[name='title']").val(json.title);
                           $("#editForm input[name='subTitle']").val(json.subTitle);
                           $("#coverImg").attr("src",json.coverUrl);
                           $("#editForm select[name='state']").val(json.state);
                           CKEDITOR.instances.editor1.setData(json.newsContent);
                       }else {
                           CKEDITOR.instances.editor1.setData("");
                       }
                       $("#newsModal").modal("show");
                   })

                   //提交按钮
                   $(".submitBtn").click(function () {
                       $("#editForm input[name='coverUrl']").val($("#coverImg").attr("src"));
                       $("#editForm input[name='newsContent.content']").val(CKEDITOR.instances.editor1.getData());
                       $("#editForm").ajaxSubmit(function (data) {
                           if (data.success) {
                               reload();
                           }else{
                               $.messager.alert(data.msg);
                           }
                       })

                   })

            })
        </script>
</head>
<body>

<div class="container " style="margin-top: 20px">
    <#include "../common/top.ftl"/>
    <div class="row">
        <div class="col-sm-3">
            <#-- 往数据模型中填充一个属性 -->
            <#assign menu="new"/>
            <#include "../common/menu.ftl"/>
        </div>
        <div class="col-sm-9">
            <div class="row">
                <div class="col-sm-12">
                    <h1 class="page-head-line">日志文章管理
                    </h1>
                </div>
            </div>
            <!--高级查询--->
            <form class="form-inline" id="searchForm" action="/new/list.do" method="post">
                <input type="hidden" name="currentPage" id="currentPage" value="1">
                <div class="form-group">
                    <label>标题:</label>
                     <input type="text" class="form-control" name="keyword" value="${(qo.keyword)!}">
                </div>
                <div class="form-group">
                    <label>时间:</label>
                    <input type="text" class="form-control" name="beignDate" style="width: 150px"
                           value="${(qo.beignDate?string("yyyy-MM-dd"))!}"
                           placeholder="请输入开始时间"> ~
                    <input type="text" class="form-control" name="endDate" style="width: 150px"
                           value="${(qo.endDate?string("yyyy-MM-dd"))!}"
                           placeholder="请输入结束时间">
                </div>
                <input type="submit" value="查询">
                <button type="button" class="btn-info inputBtn">添加</button>
            </form>

            <table class="table table-striped table-hover" >
                <tr>
                    <th>编号</th>
                    <th>标题</th>
                    <th>副标题</th>
                    <th>封面</th>
                    <th>创建时间</th>
                    <th>发布时间</th>
                    <th>状态</th>
                    <th></th>
                </tr>
                <#-- 循环迭代指令 -->
                <#list pageInfo.list as entity>
                    <tr>
                       <td>${entity_index + 1}</td>
                       <td>${entity.title}</td>
                       <td>${entity.subTitle}</td>
                       <td><img src="${entity.coverUrl}" width="60px"></td>
                       <td>${(entity.createTime?string("yyyy-MM-dd"))!}</td>
                       <td>${(entity.releaseTime?string("yyyy-MM-dd HH:mm:ss"))!}</td>
                       <td>${entity.stateName}</td>
                        <td><a role="button" class="inputBtn" data-json='${(entity.json)!}'>修改</a></td>
                    </tr>
                </#list>
            </table>
            <#include "../common/page.ftl"/>
        </div>
    </div>
</div>
<div class="modal fade" id="newsModal" tabindex="-1" role="dialog"
     aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                <h4 class="modal-title" id="myModalLabel">编辑日志文章</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" action="/new/saveOrUpdate.do" method="post" id="editForm">
                    <input type="hidden"  name="id">
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="title">
                        </div>
                    </div>
                    <div class="form-group" >
                        <label class="col-sm-4 control-label">副标题：</label>
                        <div class="col-sm-6">
                            <input type="text" class="form-control" name="subTitle">
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label" >封面：</label>
                        <div class="col-sm-6">
                            <img  id="coverImg"  width="100%" >
                            <input type="hidden" name="coverUrl">
                            <button type="button" id="fileButten">选择文件</button>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-sm-4 control-label" >状态：</label>
                        <div class="col-sm-6">
                            <select name="state" class="form-control">
                                <option value="0">草稿</option>
                                <option value="1">发布</option>
                                <option value="2">推荐</option>
                                <option value="-1">禁用</option>
                            </select>
                        </div>
                    </div>

                    <input type="hidden" name="newsContent.content">
                    <textarea  id="editor1" rows="10" cols="80" >

                     </textarea>

                    <script>
                        CKEDITOR.replace( 'editor1' );
                    </script>


                </form>
                <form id="fileForm" action="/images/xx.do" method="post" enctype="multipart/form-data"/>
                 <input id="fileBtn" type="file" class="form-control" name="file" style="display: none" accept="image/*" >
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    <span class="glyphicon glyphicon-off"></span> 关闭
                </button>
                <button type="button" class="btn btn-primary submitBtn">
                    <span class="glyphicon glyphicon-saved"></span> 保存
                </button>
            </div>
        </div>
    </div>
</div>
</body>
</html>